package com.stbu;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.stbu.bean.User;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.List;

@Controller
public class JsonController {

    @RequestMapping("/testJson")
    @ResponseBody
    public String readJson() throws JsonProcessingException {
        List<User> list = new ArrayList<>();
        User user  = new User();
        user.setId(123);
        user.setUsername("admin111");
        user.setPassword("pwd111");

        User user1 = new User();
        user1.setId(001);
        user1.setUsername("2023001");
        user1.setPassword("001001");
        ObjectMapper mapper = new ObjectMapper();

        list.add(user);
        list.add(user1);


        return mapper.writeValueAsString(list);
    }

}
